package cn.signalpha.modules.shop.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.modules.shop.dto.LogisticsDTO;
import cn.signalpha.modules.shop.entity.Logistics;
import cn.signalpha.modules.shop.service.LogisticsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/admin/logistics")
@Api(value = "物流公司", tags = "物流公司")
public class LogisticsController extends BaseController {

	private final LogisticsService logisticsService;

    @GetMapping("/page")
    @ApiImplicitParams({
        @ApiImplicitParam(name="name", dataType = "string", value = "物流名称"),
        @ApiImplicitParam(name="code", dataType = "string", value = "物流编码"),
        @ApiImplicitParam(name="codeWx", dataType = "string", value = "物流编码 微信"),
    })
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<Logistics>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
        QueryWrapper<Logistics> wrapper = logisticsService.selectLogisticsWrapper(params);
        return R.data(logisticsService.page(Condition.getPage(query), wrapper));
    }

    @GetMapping("/list")
	@ApiImplicitParams({
		@ApiImplicitParam(name="name", dataType = "string", value = "物流名称"),
		@ApiImplicitParam(name="code", dataType = "string", value = "物流编码"),
		@ApiImplicitParam(name="codeWx", dataType = "string", value = "物流编码 微信"),
	})
    @ApiOperation(value = "列表", notes = "")
    public R<List<Logistics>> list(@ApiIgnore @RequestParam Map<String, Object> params) {
        return R.data(logisticsService.list(logisticsService.selectLogisticsWrapper(params)));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<Logistics> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(logisticsService.getById(id));
	}

	@PostMapping("/update")
	@ApiOperation(value = "修改排序值", notes = "")
	public R update(@Valid @RequestBody LogisticsDTO logistics) {
		return R.status(logisticsService.updateById(BeanUtil.copy(logistics, Logistics.class)));
	}

}
